package com.lanou3g.dllo.baidumusic.main;

import android.content.Intent;
import android.graphics.Color;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import com.lanou3g.dllo.baidumusic.R;
import com.lanou3g.dllo.baidumusic.base.BaseFragment;
import com.lanou3g.dllo.baidumusic.login.UserActivity;
import com.lanou3g.dllo.baidumusic.mine.MineFragment;
import com.lanou3g.dllo.baidumusic.musiclibrary.MusicLibraryFragment;

import java.util.ArrayList;

/**
 * Created by dllo on 16/6/22.
 */
public class MainFragment extends BaseFragment{

    private TabLayout mainTabLayout;
    private ViewPager mainViewPager;
    private MainAdapter mainAdapter;
    private ArrayList<Fragment> datas;
    private ImageView mainSearch;
    private ImageView mainPersonal;

    @Override
    public int setLayout() {

        return R.layout.fragment_main;
    }

    @Override
    public void initView(View view) {

        mainTabLayout = (TabLayout) view.findViewById(R.id.main_tablayout);
        mainViewPager = (ViewPager) view.findViewById(R.id.main_viewpager);
        mainSearch = (ImageView) view.findViewById(R.id.main_search_iv);
        mainPersonal = (ImageView) view.findViewById(R.id.main_personal_iv);

    }

    @Override
    public void initData() {

        datas = new ArrayList<>();
        datas.add(new MineFragment());
        datas.add(new MusicLibraryFragment());

        mainAdapter = new MainAdapter(getFragmentManager());
        mainAdapter.setDatas(datas);
        mainViewPager.setAdapter(mainAdapter);
        mainTabLayout.setupWithViewPager(mainViewPager);
        // 设置文字颜色
        mainTabLayout.setTabTextColors(Color.GRAY, Color.WHITE);
        mainTabLayout.setSelectedTabIndicatorHeight(0);
        // 设置进去显示的界面
        mainViewPager.setCurrentItem(1);

        // 搜索
        mainSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity mainActivity = (MainActivity) getActivity();
                mainActivity .toSearch();
            }
        });

        // 个人
        mainPersonal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, UserActivity.class);
                startActivity(intent);
            }
        });

    }
}
